package model;

import java.util.Calendar;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * 
 * @author Lars
 *
 */

@Entity
@Table(name="Timestamps")
public class TimeStamp {
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private int id;
	
	@Temporal(TemporalType.TIMESTAMP)
	private Calendar tid;
	
	@ManyToOne
	private Mellemvare mellemvare;
	
	@ManyToOne
	private DelBehandling delBehandling;
	
	public TimeStamp() {
		// JPA
	}
	
	public TimeStamp(Calendar tid) {
		this.tid = tid;
	}
	
	public TimeStamp(Calendar tid, Mellemvare mellemvare, DelBehandling delBehandling) {
		this.tid = tid;
		this.setMellemvareUD(mellemvare);
		this.setDelBehandlingUD(delBehandling);
	}
	
	public Calendar getTid() {
		return this.tid;
	}

	public void setMellemvareUD(Mellemvare mellemvare) {
		this.mellemvare = mellemvare;
	}
	
	public void setMellemvare(Mellemvare mellemvare){
		if(mellemvare != null){
			this.setMellemvareUD(mellemvare);
			mellemvare.addTimeStampUD(this);
		}
		else {
			this.getMellemvare().removeTimeStampUD(this);
			this.setMellemvare(null);
		}
	}

	public Mellemvare getMellemvare() {
		return mellemvare;
	}

	public void setDelBehandlingUD(DelBehandling delBehandling) {
		this.delBehandling = delBehandling;
	}

	public DelBehandling getDelBehandling() {
		return delBehandling;
	}
	
	public TimeStamp copyTid(){
		return new TimeStamp(this.tid);
	}
}
